package com.baosight.sczx.zm.cg.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ef.chart.ChartUtils;
import com.baosight.iplat4j.ef.chart.EfChart;
import com.baosight.iplat4j.ef.chart.chartElement.CEApply;
import com.baosight.iplat4j.ef.chart.chartElement.CEDataSeries;
import com.baosight.iplat4j.ef.chart.chartElement.styleImpl.SAnimation;
import com.baosight.iplat4j.ef.chart.chartElement.styleImpl.SFont;
import com.baosight.iplat4j.ef.chart.service.ServiceChartBase;
import com.baosight.sczx.zm.cg.domain.ZMCGPictureShow;
import com.baosight.sczx.zm.cp.domain.ZMCPProfessionalPlan;

public class ServiceZMCGG01 extends ServiceChartBase{
	
	/**
	 * 初始化
	 */
	@SuppressWarnings("rawtypes")
	List yuePlan,yueActual;
	@SuppressWarnings("rawtypes")
	List januaryData = new ArrayList(),februaryData = new ArrayList(),marchData = new ArrayList(),aprilData = new ArrayList(),mayData = new ArrayList(),juneData = new ArrayList(),
		 julyData = new ArrayList(),augustData = new ArrayList(),septemberData = new ArrayList(),octoberData = new ArrayList(),novemberData = new ArrayList(),decemberData = new ArrayList();
	
	public String[] genInitChartInfo(EiInfo info){
		StringBuffer sb = new StringBuffer();
		sb.append(ChartUtils.chartAttr2Str("bgcolor",info.getString("bgcolor")));
		sb.append(ChartUtils.chartAttr2Str("canvasBgColor",info.getString("canvasBgColor")));
		sb.append(ChartUtils.chartAttr2Str("showValues",info.getString("showValues")));
		
	    return new String[]{"年计划实际对比","月份","销售量",null,null,null,null,sb.toString()};
	}
	
	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCGG01</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016-09-12 上午14:47:20 卢健
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) 
	{
		String fdNf = inInfo.getString("year");
		String fdMiningId = UserSession.getInSessionProperty("miningCode").toString();
		Map<String, String>	params = new HashMap<String, String>();
        params.put("fdVirtualDate", fdNf);
        params.put("fdMiningId", fdMiningId);
        yueActual = dao.query("ZMCGDispatchDaily.queryMine",params);//月实际
        
		params.put("fdPlanYear", fdNf);
		yuePlan = dao.query("ZMCPProfessionalPlan.queryMine",params);//月计划
		return inInfo;
	}
	
	/**
	 * category
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public List genChartCatLabels(EiInfo info){
		List list = new ArrayList();

		list.add("一月");
		list.add("二月");
		list.add("三月");
		list.add("四月");
		list.add("五月");
		list.add("六月");
		list.add("七月");
		list.add("八月");
		list.add("九月");
		list.add("十月");
		list.add("十一月");
		list.add("十二月");

		return list;
	}
			
	public void setChartStyle(EiInfo info, EfChart chart){
		if(!"1".equals(info.getString("dataType"))){
			//样式--定义
			SAnimation animation = new SAnimation("Anim1");
			animation.setParam("_yScale");
			animation.setStart("0");
			animation.setDuration("1");
			chart.addStyleDefinition(animation);
			
			SAnimation animation2 = new SAnimation("Anim2");
			animation2.setParam("_alpha");
			animation2.setStart("0");
			animation2.setDuration("5");
			animation2.setEasing("strong");
			chart.addStyleDefinition(animation2);
			
			//设置ShowValues背景及显示字体颜色
			SFont font = new SFont("font1");
			font.setBorderColor("1D8BD1");
			font.setBgColor("1D8BD1");
			font.setColor("FFFFFF");
			chart.addStyleDefinition(font);
			//样式--应用
			chart.addStyleApply(new CEApply(animation,"VLINES"));
			chart.addStyleApply(animation2,"TRENDLINES");
			chart.addStyleApply(font,"DATAVALUES");
		}
	}
	
	protected boolean isMData(EiInfo info){
		if(!"1".equals(info.getString("dataType"))){
			return true;
		}
		return false;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected List genSeriesNames(EiInfo info){

		List list = new ArrayList();
		list.add("实际");
		list.add("计划");
		return list;
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected List genMChartDataValues(EiInfo info){
		BigDecimal fdYmSum = new BigDecimal("0");
		String fdMonth;
		
		String januarySJ = "0",februarySJ = "0",marchSJ = "0",aprilSJ = "0",maySJ = "0",juneSJ = "0",julySJ = "0",augustSJ = "0",septemberSJ = "0",octoberSJ = "0",novemberSJ = "0",decemberSJ = "0";
		String january = "0",february = "0",march = "0",april = "0",may = "0",june = "0",july = "0",august = "0",september = "0",october = "0",november = "0",december = "0";
        /*月实际*/
		if(yueActual!= null && yueActual.size()>0){
			for(int r=0;r<yueActual.size();r++){
				ZMCGPictureShow bean = (ZMCGPictureShow)yueActual.get(r);
				fdMonth = bean.getFdMonth();
				fdYmSum = bean.getFdMinesumMsum();

				if(fdMonth !=null && ("01").equals(fdMonth)){
					 januarySJ = fdYmSum.toString();
				}
				if(fdMonth !=null && ("02").equals(fdMonth)){
					 februarySJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("03").equals(fdMonth)){
					 marchSJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("04").equals(fdMonth)){
					 aprilSJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("05").equals(fdMonth)){
					 maySJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("06").equals(fdMonth)){
					 juneSJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("07").equals(fdMonth)){
					 julySJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("08").equals(fdMonth)){
					 augustSJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("09").equals(fdMonth)){
					 septemberSJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("10").equals(fdMonth)){
					 octoberSJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("11").equals(fdMonth)){
					 novemberSJ  = fdYmSum.toString();
				}
				if(fdMonth !=null && ("12").equals(fdMonth)){
					 decemberSJ  = fdYmSum.toString();
				}
			}
		}
		/*月计划*/
		if(yuePlan!= null && yuePlan.size()>0){
			for(int i=0;i<yuePlan.size();i++){
				ZMCPProfessionalPlan bean1 = (ZMCPProfessionalPlan)yuePlan.get(i);
				fdYmSum = bean1.getFdYmSum();
				String ymSum = fdYmSum.toString();
				String month = bean1.getFdPlanMonth();
				if(month !=null && ("01").equals(month)){
					 january = ymSum;
				}
				if(month !=null && ("02").equals(month)){
					 february  = ymSum;
				}
				if(month !=null && ("03").equals(month)){
					 march  = ymSum;
				}
				if(month !=null && ("04").equals(month)){
					 april  = ymSum;
				}
				if(month !=null && ("05").equals(month)){
					 may  = ymSum;
				}
				if(month !=null && ("06").equals(month)){
					 june  = ymSum;
				}
				if(month !=null && ("07").equals(month)){
					 july  = ymSum;
				}
				if(month !=null && ("08").equals(month)){
					 august  = ymSum;
				}
				if(month !=null && ("09").equals(month)){
					 september  = ymSum;
				}
				if(month !=null && ("10").equals(month)){
					 october  = ymSum;
				}
				if(month !=null && ("11").equals(month)){
					 november  = ymSum;
				}
				if(month !=null && ("12").equals(month)){
					 december  = ymSum;
				}
			}
		}
		
		
		
		List list = new ArrayList();
		
		List list1 = new ArrayList();
		list1.add(januarySJ);
		list1.add(februarySJ);
		list1.add(marchSJ);
		list1.add(aprilSJ);
		list1.add(maySJ);
		list1.add(juneSJ);
		list1.add(julySJ);
		list1.add(augustSJ);
		list1.add(septemberSJ);
		list1.add(octoberSJ);
		list1.add(novemberSJ);
		list1.add(decemberSJ);
		list.add(list1);
		
		List list2 = new ArrayList();//月计划
		list2.add(january);
		list2.add(february);
		list2.add(march);
		list2.add(april);
		list2.add(may);
		list2.add(june);
		list2.add(july);
		list2.add(august);
		list2.add(september);
		list2.add(october);
		list2.add(november);
		list2.add(december);
		list.add(list2);
		
		
		return list;
	}

	/**
	 * 设置对应柱状显示颜色
	 * @return
	 */	
	@SuppressWarnings("rawtypes")
	protected List genMChartDatasetList(EiInfo info){
		List list = super.genMChartDatasetList(info);
		
		CEDataSeries datasetSeries1 = (CEDataSeries)list.get(0);
		datasetSeries1.setColor("FF7FFF");
		datasetSeries1.setShowValues("1");
		
		CEDataSeries datasetSeries2 = (CEDataSeries)list.get(1);
		datasetSeries2.setColor("FF0000");
		datasetSeries2.setShowValues("1");
		
		return list;
	}
}
